package com.youlai.system.controller;

import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.model.dto.OrderByCategoryTotalDTO;
import com.youlai.system.model.dto.OrderDto;
import com.youlai.system.model.dto.OrderItemDto;
import com.youlai.system.model.dto.OrderTotalDto;
import com.youlai.system.model.vo.*;
import com.youlai.system.service.OrderItemService;
import com.youlai.system.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cai
 * @create 2024-03-11 22:54
 */
@Tag(name = "订单接口")
@RestController
@RequestMapping("/api/v1/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;
    private final OrderItemService orderItemService;

    @Operation(summary = "订单列表")
    @GetMapping("/page")
    public PageResult<OrderVO> getPage(@ParameterObject OrderDto orderDto){
        return orderService.getPage(orderDto);
    }

    @Operation(summary = "订单物品列表")
    @GetMapping("/item/page")
    public PageResult<OrderItemVO> getPage(@ParameterObject OrderItemDto orderItemDto){
        return orderItemService.getPage(orderItemDto);
    }

    @Operation(summary = "商品总订单统计")
    @GetMapping("/total")
    public Result getTotal(@ParameterObject OrderTotalDto orderTotalDto){
        List<OrderTotalVO> orderTotalVOList= orderService.getTotal(orderTotalDto);
        return Result.success(orderTotalVOList);
    }

    @Operation(summary = "商品分类订单统计")
    @GetMapping("/category/total")
    public Result getCategoryTotal(@ParameterObject OrderByCategoryTotalDTO orderByCategoryTotalDTO){
        // System.out.println(orderByCategoryTotalDTO);
        List<OrderByCategoryTotalVO> orderByCategoryTotalVOList = orderService.getCategoryTotal(orderByCategoryTotalDTO);
        return Result.success(orderByCategoryTotalVOList);
    }

    @Operation(summary = "订单总量统计（日、周、月）")
    @GetMapping("/total/statistics")
    public Result getTotalStatistics(@ParameterObject String type){
        List<OrderTotalStatisticsVO> orderTotalStatisticsVOList = orderService.getTotalStatistics(type);
        return Result.success(orderTotalStatisticsVOList);
    }
}
